<!-- 企业信息查询 -->
<template>
  <div class="project-inquiry">
    <Form ref="formData" :model="formData" :label-width="80">
      <Row :gutter="30">
        <Col span="6">
          <FormItem label="项目名称" prop="projectName">
            <Input v-model="formData.projectName" placeholder="请输入"></Input>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="地区" prop="city">
            <CityCascader ref="cityCascader" @getProvince="getProvince" />
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="重复率" prop="repetitionRate">
            <Select
              v-model="formData.repetitionRate"
              placeholder="全部"
              clearable
            >
              <Option
                :value="value"
                v-for="(label, value) in EnumRepetitionRate"
                :key="value"
                >{{ label }}</Option
              >
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row :gutter="30">
        <Col span="6">
          <FormItem label="发布时间" prop="times">
            <DatePicker
              v-model="formData.times"
              format="yyyy/MM/dd"
              type="daterange"
              placeholder="请选择时间"
              style="width: 100%"
            ></DatePicker>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="审核状态" prop="auditStatus">
            <Select v-model="formData.auditStatus" placeholder="全部" clearable>
              <Option
                :value="value"
                v-for="(label, value) in EnumAuditStatus"
                :key="value"
                >{{ label }}</Option
              >
            </Select>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="接收状态" prop="acceptStatus">
            <Select
              v-model="formData.acceptStatus"
              placeholder="全部"
              clearable
            >
              <Option
                :value="value"
                v-for="(label, value) in EnumReceiveStatus"
                :key="value"
                >{{ label }}</Option
              >
            </Select>
          </FormItem>
        </Col>

        <Col span="6" class="com-action-search-btn">
          <Button
            type="primary"
            icon="md-search"
            @click="handleSubmit('formData')"
            >查询</Button
          >
          <BtnPlain type="primary" @click="handleReset('formData')">
            <Icon type="md-refresh" />
            <span>重置</span>
          </BtnPlain>
        </Col>
      </Row>
    </Form>
    <Table :columns="columns" :data="listData">
      <template slot-scope="{ row }" slot="repetitionRate">
        <BtnPlain type="primary">{{ row.repetitionRate + "%" }}</BtnPlain>
      </template>
      <template slot-scope="{ row }" slot="location">
        <BtnText type="primary" @BtnClick="onViewLocation(row)"
          >查看定位</BtnText
        >
      </template>
      <template slot-scope="{ row }" slot="auditStatus">
        <BtnPlain :type="row.auditStatus | getAuditStatus">{{
          row.auditStatusName
        }}</BtnPlain>
      </template>
      <template slot-scope="{ row }" slot="acceptStatus">
        <BtnPlain :type="row.acceptStatus | getAcceptStatus">{{
          row.acceptStatusName
        }}</BtnPlain>
      </template>
      <template slot-scope="{ row }" slot="view">
        <BtnText
          v-if="row.rootInformationEnum === 'Derivative'"
          type="primary"
          @BtnClick="onSourceInfo(row)"
          >查看源信息</BtnText
        >
      </template>
      <template slot-scope="{ row }" slot="action">
        <BtnText type="primary" @BtnClick="onView(row, 'view')">详情</BtnText>
        <BtnText
          v-if="showActionBtn('审核', row)"
          type="warning"
          @BtnClick="onView(row, 'examine')"
          >审核</BtnText
        >
        <BtnText
          v-if="showActionBtn('接收', row)"
          type="green"
          @BtnClick="onView(row, 'receive')"
          >接收</BtnText
        >
        <BtnText
          v-if="showActionBtn('反馈', row)"
          type="error"
          @BtnClick="onView(row, 'feedback')"
          >反馈</BtnText
        >
      </template>
    </Table>
    <PageAtion
      v-if="formData.total"
      :total="formData.total"
      :size.sync="formData.size"
      :page.sync="formData.page"
      @pageSizeChange="pageSizeChange"
    />
    <SourceInfo v-model="modalValue" :parentId="tableParentId" />
    <ViewLocation v-model="modalValueLocation" :info="locationInfo" />
  </div>
</template>

<script>
import SourceInfo from "./common/sourceInfo.vue";
import ViewLocation from "./common/viewLocation.vue";
import { busiInfoGetPage } from "@/api/businessInformationManage.js";
import CityCascader from "@/pages/components/cityCascader";

export default {
  name: "projectInquiry",
  components: { SourceInfo, ViewLocation, CityCascader },
  data() {
    return {
      tableParentId: "",
      formData: {
        projectName: "",
        auditStatus: "",
        acceptStatus: "",
        publishTimeStart: "",
        publishTimeEnd: "",
        times: [],
        repetitionRate: "",
        province: "",
        city: "",
        page: 1,
        size: 10,
        total: 10,
      },
      columns: [
        {
          title: "项目名称",
          key: "projectName",
          minWidth: 160,
          tooltip: true,
        },
        {
          title: "信息类型",
          key: "infoTypeName",
          minWidth: 160,
          tooltip: true,
        },
        {
          title: "重复率",
          key: "repetitionRate",
          slot: "repetitionRate",
          minWidth: 120,
        },
        {
          title: "省份",
          key: "province",
          minWidth: 120,
        },
        {
          title: "城市",
          key: "city",
          minWidth: 120,
        },
        {
          title: "产业标记",
          key: "industryAssign",
          minWidth: 160,
          tooltip: true,
        },
        {
          title: "项目位置",
          slot: "location",
          minWidth: 120,
        },
        {
          title: "业主方",
          key: "ownerCompanyName",
          minWidth: 160,
          tooltip: true,
        },
        {
          title: "施工方",
          key: "constructionName",
          minWidth: 160,
          tooltip: true,
        },
        {
          title: "预计产值规模(万元)",
          key: "outputScale",
          minWidth: 160,
        },
        {
          title: "项目阶段",
          key: "projectStageName",
          minWidth: 100,
        },
        {
          title: "项目备注",
          key: "projectRemark",
          minWidth: 200,
          tooltip: true,
        },
        {
          title: "推送目标企业",
          key: "pushCompany",
          minWidth: 240,
          tooltip: true,
        },
        {
          title: "发布人",
          key: "publisher",
          minWidth: 120,
        },
        {
          title: "发布时间",
          key: "publishTime",
          minWidth: 170,
        },
        {
          title: "审核状态",
          slot: "auditStatus",
          minWidth: 160,
        },
        {
          title: "接受状态",
          slot: "acceptStatus",
          minWidth: 160,
        },
        {
          title: "派生信息标签",
          slot: "view",
          minWidth: 160,
        },
        {
          title: "操作",
          slot: "action",
          width: 170,
          align: "center",
          fixed: "right",
        },
      ],
      listData: [],
      modalValue: false,
      modalValueLocation: false,
      // 审核状态
      EnumAuditStatus: {
        UnderReview: "审核中",
        Pass: "通过",
        NotPass: "驳回",
        CancelAudit: "已撤回",
      },
      // 接收状态
      EnumReceiveStatus: {
        UnReceive: "未接收",
        Receive: "已接收",
        SectionReceive: "部分接收",
        Rejection: "已拒绝",
      },
      // 重复率
      EnumRepetitionRate: {
        20: "20%",
        40: "40%",
        60: "60%",
        80: "80%",
        100: "100%",
      },
      locationInfo: {},
    };
  },
  created() {
    this.init();
  },
  methods: {
    async init(companyId = "") {
      const request = {
        ...this.formData,
        publishTimeStart: this.formData.times[0],
        publishTimeEnd: this.formData.times[1],
        orgId: companyId,
      };
      const { data, page, size, total } = await busiInfoGetPage(request);
      this.listData = data;
      this.formData = { ...this.formData, ...{ page, size, total } };
    },
    getProvince(arr) {
      this.formData.province = arr[0] || "";
      this.formData.city = arr[1] || "";
    },
    handleReset(name) {
      this.$refs["cityCascader"].reset();
      this.$refs[name].resetFields();
      this.init();
    },
    handleSubmit(name) {
      this.formData.page = 1;
      this.init();
    },
    pageSizeChange(row) {
      this.init();
    },
    // 查看来源信息
    onSourceInfo(row) {
      this.tableParentId = row.parentId;
      this.modalValue = true;
    },
    // 详情
    onView(row, type) {
      const { busiInfoId } = row;
      this.$router.push({
        path: "/businessInformationDetails",
        query: { busiInfoId, type },
      });
    },
    onViewLocation(row) {
      this.modalValueLocation = true;
      this.locationInfo = row;
    },
    showActionBtn(type, row) {
      let flag = false;
      switch (type) {
        case "接收":
          flag =
            row.auditStatus === "Pass" &&
            (row.acceptStatus === "UnReceive" ||
              row.acceptStatus === "SectionReceive");
          break;
        case "反馈":
          flag =
            row.acceptStatus === "Receive" ||
            row.acceptStatus === "SectionReceive";
          break;
        case "审核":
          flag = row.auditStatus === "UnderReview";
          break;
      }
      return flag;
    },
  },
};
</script>

<style lang="less">
.project-inquiry .badge-alone {
  border-radius: 3px;
  padding: 0;
  min-width: 15px;
  height: 15px;
  font-size: 11px;
  line-height: 13px;
}
</style>
